﻿using System.Collections.Generic;
using UnityEngine;

public static class TransformExtension
{
    /// <summary>
    /// 获得激活物体的数量
    /// </summary>
    /// <param name="transform"></param>
    public static int GetActiveChildCount(this Transform transform)
    {
        List<Transform> children = new();
        for (int i = 0; i < transform.childCount; i++)
        {
            if (transform.GetChild(i).gameObject.activeSelf)
            {
                children.Add(transform.GetChild(i));
            }
        }
        return children.Count;
    }
    /// <summary>
    /// 获得一个激活的物体
    /// </summary>
    /// <param name="transform"></param>
    /// <returns></returns>
    public static Transform GetActiveChild(this Transform transform)
    {
        for (int i = 0; i < transform.childCount; i++)
        {
            if (transform.GetChild(i).gameObject.activeSelf)
            {
                return transform.GetChild(i);
            }
        }
        return null;
    }
}
